//headers 
#include<algorithm>
#include<cassert>
#include<cstdio>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<deque>
#include<set>
#include<string>
#include<sstream>
#include<stack>
#include<streambuf>
#include<vector>
using namespace std;

//macros
#define LET(x,a) typeof(a) x(a)
#define FOR(i,a,n) for(LET(i,a);i!=n;i++)
#define REP(i,n) FOR(i,0,n)
#define sz size()
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define dbge(x) cout<<#x<<"->"<<x<<endl;
#define PRINT(x) REP(_,x.sz) cout<<x[_]<<" "; cout<<endl;
#define OUT(x) x<<" "
const int INF = (int) 1e8;
#define VI vector<int>
#define VS vector<string>
#define VVI vector< vector<int> >
#define LL long long

//code of suren

bool palin(string a){
  string b = a; reverse(ALL(b));
  if(a==b) return true;
  return false;
}

LL reverse(LL a) {
  LL rev = 0;
  while (a) {
    rev *= 10;
    rev += a % 10;
    a /= 10;
  }
  return rev;
}

int main(){
  int n; cin>>n;
  while(n--){
    LL num; cin>>num; int count=0;
    LL rev = reverse(num);
    while( rev != num){
      num = rev + num ;
      rev = reverse(num);
      count++;
    }
    cout<<count<<" "<<num<<endl;
  }
  return 0;
}
